package hu.elte.inf.holiuml.fileutil;

import javax.xml.bind.JAXBException;

/**
 * Factory for persister and code generator classes.
 * Currently supports:
 * Persisters: XML (coming: binary)
 * Code Generator: Java (coming: c++)
 * 
 * @author Jozsef Sipos
 *
 */
public class FileUtilFactory {
	
	/**
	 * For details @see PersistenceService, @see XMLPersister
	 * @return the default XML Persister instance
	 */
	public static PersistenceService getXMLPersister() {
		try {
			return XMLPersister.getInstance();
		} catch (JAXBException e) {
			/* JAXB context cannot be created.
			 * Should not occur, since the Document
			 * class is checked for JAXB-compliance.
			 * 
			 * However the UI layer should catch any
			 * RuntimeException, and inform the user
			 * about open and save will be unavailable. 
			 */ 
			throw new RuntimeException(e);
		}
	}
	
	/*
	public static PersistenceService getBinaryPersister() {
		return BinaryPersister.getInstance();
	}
	*/
	
	/**
	 * For details @see CodeGenerator, @see JavaCodeGenerator
	 * @return the default Java Code Generator instance
	 */
	public static CodeGenerator getJavaGenerator() {
		return new JavaCodeGenerator();
	}

	private static int nextId = 0;
	public static String getNextId() {
		return String.valueOf(++nextId);
	}
	
	/*
	public static CodeGenerator getCPPGenerator() {
		return null;
	} 
	*/

}
